home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions ThresholdTransmitter component
-
- #include "NSDLL.h"
-
- BOOL averageLessThan(NSFloat *, int, NSFloat);
- BOOL allLessThan(NSFloat *, int, NSFloat);
- BOOL oneLessThan(NSFloat *, int, NSFloat);
-
- /******************************************/
- /* Decide when to send transmitter action */
-
- __declspec(dllexport) BOOL performThresholdTransmitter(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *data, // Pointer to the data to be accessed
- int rows, // Number of rows of access data
- int cols, // Number of columns of access data
- NSFloat threshold, // Threshold specified within the compontents inspector
- BOOL lessThan, // Less than/greater than state as specified within inspector
- int type, // Threshold type, 0=All 1=One 2=Average 3=Individual
- int channelNumber
- )
- {
- int length=rows*cols;
-
- switch (type) {
- case 0:
- if (lessThan)
- return allLessThan(data,length,threshold);
- return !oneLessThan(data,length,threshold);
- break;
- case 1:
- if (lessThan)
- return oneLessThan(data,length,threshold);
- return !allLessThan(data,length,threshold);
- break;
- case 2:
- if (lessThan)
- return averageLessThan(data,length,threshold);
- return !averageLessThan(data,length,threshold);
- break;
- case 3:
- if (lessThan)
- return oneLessThan(data+channelNumber,1,threshold);
- return !allLessThan(data+channelNumber,1,threshold);
- break;
- }
- return NO;
- }
-
- BOOL oneLessThan(NSFloat *data, int length, NSFloat threshold)
- {
- register int i;
-
- for (i=0; i<length; i++)
- if (data[i] < threshold)
- return YES;
- return NO;
- }
-
- BOOL allLessThan(NSFloat *data, int length, NSFloat threshold)
- {
- register int i;
-
- for (i=0; i<length; i++)
- if (data[i] > threshold)
- return NO;
- return YES;
- }
-
- BOOL averageLessThan(NSFloat *data, int length, NSFloat threshold)
- {
- register int i;
- register NSFloat average = (NSFloat)0.0;
-
- for (i=0; i<length; i++)
- average += data[i];
- return (average /= length) < threshold;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocThresholdTransmitter(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int rows, // Number of rows of PEs in the layer
- int cols // Number of columns of PEs in the layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeThresholdTransmitter(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */